home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / ProgressMonitorInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  1.8 KB  |  95 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Component;
  4. import java.io.FilterInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.InterruptedIOException;
  8.  
  9. public class ProgressMonitorInputStream extends FilterInputStream {
  10.    private ProgressMonitor monitor;
  11.    private int nread = 0;
  12.    private int size = 0;
  13.  
  14.    public ProgressMonitorInputStream(Component var1, Object var2, InputStream var3) {
  15.       super(var3);
  16.  
  17.       try {
  18.          this.size = var3.available();
  19.       } catch (IOException var4) {
  20.          this.size = 0;
  21.       }
  22.  
  23.       this.monitor = new ProgressMonitor(var1, var2, (String)null, 0, this.size);
  24.    }
  25.  
  26.    public void close() throws IOException {
  27.       super.in.close();
  28.       this.monitor.close();
  29.    }
  30.  
  31.    public ProgressMonitor getProgressMonitor() {
  32.       return this.monitor;
  33.    }
  34.  
  35.    public int read() throws IOException {
  36.       int var1 = super.in.read();
  37.       if (var1 >= 0) {
  38.          this.monitor.setProgress(++this.nread);
  39.       }
  40.  
  41.       if (this.monitor.isCanceled()) {
  42.          InterruptedIOException var2 = new InterruptedIOException("progress");
  43.          var2.bytesTransferred = this.nread;
  44.          throw var2;
  45.       } else {
  46.          return var1;
  47.       }
  48.    }
  49.  
  50.    public int read(byte[] var1) throws IOException {
  51.       int var2 = super.in.read(var1);
  52.       if (var2 > 0) {
  53.          this.monitor.setProgress(this.nread += var2);
  54.       }
  55.  
  56.       if (this.monitor.isCanceled()) {
  57.          InterruptedIOException var3 = new InterruptedIOException("progress");
  58.          var3.bytesTransferred = this.nread;
  59.          throw var3;
  60.       } else {
  61.          return var2;
  62.       }
  63.    }
  64.  
  65.    public int read(byte[] var1, int var2, int var3) throws IOException {
  66.       int var4 = super.in.read(var1, var2, var3);
  67.       if (var4 > 0) {
  68.          this.monitor.setProgress(this.nread += var4);
  69.       }
  70.  
  71.       if (this.monitor.isCanceled()) {
  72.          InterruptedIOException var5 = new InterruptedIOException("progress");
  73.          var5.bytesTransferred = this.nread;
  74.          throw var5;
  75.       } else {
  76.          return var4;
  77.       }
  78.    }
  79.  
  80.    public synchronized void reset() throws IOException {
  81.       super.in.reset();
  82.       this.nread = this.size - super.in.available();
  83.       this.monitor.setProgress(this.nread);
  84.    }
  85.  
  86.    public long skip(long var1) throws IOException {
  87.       long var3 = super.in.skip(var1);
  88.       if (var3 > 0L) {
  89.          this.monitor.setProgress(this.nread = (int)((long)this.nread + var3));
  90.       }
  91.  
  92.       return var3;
  93.    }
  94. }
  95.